package com.flipdf2.serialize.ppml.element;

import java.awt.geom.Rectangle2D;

import org.jdom.Element;
import org.jdom.Namespace;

import com.flipdf2.serialize.ppml.PPMLException;

public class PPMLClipRect {
	public static final String NAME = "CLIP_RECT";
	
	private Rectangle2D.Double rectangle;
	
	public Element toXML(Namespace defaultNamespace) {
		Element root = null;
		if (defaultNamespace != null) {
			root = new Element(NAME, defaultNamespace);
		} else {
			root = new Element(NAME);	
		}
		
		root.setAttribute("Rectangle", this.rectangle.x + " " + 
				this.rectangle.y + " " + 
				this.rectangle.width + " " + 
				this.rectangle.height);
		return root;
	}
	
	public void check() throws PPMLException {
		if (rectangle == null) {
			throw PPMLException.getInstance(PPMLException.REQUIRED_ATTRIBUTE_LOST, "Rectangle");
		}
	}

	public Rectangle2D.Double getRectangle() {
		return rectangle;
	}

	public void setRectangle(Rectangle2D.Double rectangle) {
		this.rectangle = rectangle;
	}
}
